<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

class News extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'default';

    protected $table = 'news';

    public function _initialize(){
        parent::_initialize();

    }

    public function index()
    {

        $data = Db::name($this->table)->order('weigh desc,id desc')->paginate(5);
        $page = $data->render();
        $this->assign('page',$page);
        $this->assign('lists', $data);
        return $this->view->fetch();
    }

    public function detail()
    {
        $id = input('id/d','');

        $data = Db::name($this->table)->where('id',$id)->find();
        Db::name($this->table)->where('id',$id)->setInc('hits');
        $this->assign('detail',$data);

        $next = Db::name($this->table)->where('id','>',$id)->order('id asc')->find();
        $this->assign('next',$next);
        $prev = Db::name($this->table)->where('id','<',$id)->order('id desc')->find();
        $this->assign('prev',$prev);

        return $this->view->fetch();
    }

}
